package com.pine.sunshineelder.checkin.web.handler;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pine.sunshineelder.checkin.ao.relative.relativeAddAo;
import com.pine.sunshineelder.checkin.ao.relative.relativeModAo;
import com.pine.sunshineelder.checkin.service.RelativeService;
import com.pine.sunshineelder.common.dto.JSONResponse;
import com.pine.sunshineelder.common.entity.RelativeEntity;

@RestController
@RequestMapping("/api")
public class RelationHandler {
	@Autowired
     RelativeService service;
	@PostMapping("/relative/{elderId}")
	public JSONResponse registerRelation(@PathVariable String elderId,@Valid relativeAddAo ao)throws Exception{
		RelativeEntity updateRelative = service.updateRelative(elderId, ao);
		return JSONResponse.ok(updateRelative);
		
	}
	@PutMapping("/relative/{id}")
	public JSONResponse modifyRelation(@PathVariable String id ,@Valid relativeModAo ao)throws Exception{
		RelativeEntity modifyRelative = service.modifyRelative(id, ao);
		return JSONResponse.ok(modifyRelative);
	}
	@GetMapping("/relative/{id}")
	public RelativeEntity loadOne( @PathVariable String id)throws Exception{
		RelativeEntity queryById = service.queryById(id);
		return queryById;
		
	}
}
